package link.wangkui.utils;
import com.alibaba.excel.util.StringUtils;
import com.alibaba.excel.write.metadata.style.WriteFont;

import java.io.File;
import java.io.InputStream;
public class TestFileUtil {
    public static InputStream getResourcesFileInputStream(String fileName) {
        return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName);
    }

    public static String getPath() {
        return TestFileUtil.class.getResource("/").getPath();
    }

    public static File createNewFile(String pathName) {
        File file = new File(getPath() + pathName);
        if (file.exists()) {
            file.delete();
        } else {
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
        }
        return file;
    }

    public static File readFile(String pathName) {
        return new File(getPath() + pathName);
    }

    public static File readUserHomeFile(String pathName) {
        return new File(System.getProperty("user.home") + File.separator + pathName);
    }

    /**
     * @purpose 设置字体
     * @parameter name为null表示不设置字体
     */
    public static WriteFont setFont(int size, String name, boolean condition) {
        WriteFont font = new WriteFont();
        // 大小
        font.setFontHeightInPoints((short) size);
        // 字体
        if (!StringUtils.isEmpty(name)) {
            font.setFontName(name);
        }
        // 是否加粗
        font.setBold(condition);
        return font;
    }
}
